﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MyAppBox.Controllers;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;

namespace MyAppBox.Areas.system.Controllers
{
    [Area("system")]
    public class system16Controller : SysPageController
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            InitPage(null, null);
            List<FineUICore.ListItemExtension> listitem = GetDDLitemBySys5code("009");
            ViewBag.ddlmodeldata = listitem.ToArray();
            return View();
        }

        public void InitPage(MsQuery _msq, JArray fields)
        {
            MsQuery msq = new MsQuery();
            if (_msq != null)
            {
                msq = _msq;
            }
            msq.strorder = "System_16_80 desc";
            DataTable dt = ((DataSet)(new BLLsystem_16().Getsystem_16ByQuery(msq).data)).Tables[0];

            if (!FineUICore.PageContext.IsFineUIAjaxPostBack())
            {
                ViewBag.griddata = dt;
            }
            else
            {
                var Grid1 = FineUICore.UIHelper.Grid("Grid1");
                Grid1.DataSource(dt, fields);
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Grid1Del_Click(JArray id, JArray fields)
        {
            MsQuery msq = new MsQuery();
            msq.strquery = " and SYSTEM_16_10 in ('" + string.Join("','", id) + "')";
            MsReturned rt = new BLLsystem_16().Deletesystem_16ByQuery(msq);
            if (Convert.ToInt32(rt.strMsId) >= 0)
            {
                ShowNotify("保存成功");
                //InitPage(null, fields);
                FineUICore.PageContext.RegisterStartupScript("search_Click();");
            }
            return FineUICore.UIHelper.Result();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult lodeGrid(JObject querydata, JArray fields)
        {
            MsQuery msq = new MsQuery();
            Mssystem_16 ms = Mssystem_16.parse(querydata);
            if (!string.IsNullOrEmpty(ms.System_16_40))
            {
                msq.strquery += " and System_16_40 ='" + ms.System_16_40 + "'";

            }

            InitPage(msq, fields);
            return FineUICore.UIHelper.Result();
        }
    }
}